<template>
	<view class="search">
		<view class="search-header">
			<u-search :show-action="true" placeholder="昵称/手机号/邮箱" action-text="取消" height="64" shape="square" v-model="keyword" @custom="actCancel" :focus="true" @search="actSearch" ></u-search>
		</view>
		<view class="search-content" v-if="isResult">
			<scroll-view scroll-y="true" v-if="JSON.parse(JSON.stringify(list)).length > 0">
				<view class="u-flex result-item" v-for="(item, index) in list"  @click.stop="goUser" :data-uid="item.Uid">
					<u-image v-if="item.Avatar" width="112rpx" height="112rpx" border-radius="112rpx" :src="item.Avatar"></u-image>
					<u-image v-else width="112rpx" height="112rpx" border-radius="112rpx" src="/static/images/avatar.jpg"></u-image>
					<view class="u-flex-1 result-item_info">
						<view class="name">{{item.Nickname }}</view>
						<view class="u-flex result-item_info--cell">
							<text class="label">邮箱:</text>
							<view class="value">{{ item.Email }}</view>
						</view>
						<view class="u-flex result-item_info--cell">
							<text class="label">手机:</text>
							<view class="value">{{ item.Mobile }}</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
		<u-modal v-model="isAdd" :show-cancel-button="true" :show-title="false" cancelText="考虑一下" confirmText="确定" :content="'确定添加'+'好友吗'" @confirm="actConfirm"></u-modal>
	</view>
</template>

<script>
	import  articleItem from "@/components/article-item/index.vue";
  import pageMixin from '@/utils/pageMixin';
  export default {
    mixins: [pageMixin],
		data() {
			return {
				iconType: 'flower',
				list:[],
				keyword:'',
				isResult:true,
				isAdd:false,
				user:''
			}
		},

		onLoad() {
			
		},
		onShow() {
		},
		components: {
			articleItem
		},
		methods: {
			getList() {
				this.$http.get('/client/user/account/list', {user:this.user}).then(res => {
					this.list = res;
					if(res.length > 0){
						this.isResult = true;
					}else{
						this.isResult = false;
					}
				})
			},
			actCancel() {
				this.$u.route({
					type: 'back'
				})
			},
			actSearch(e){
				this.user = e;
				if(e == ''){
					this.list = [];
				}else{
					this.getList();
				}
				// let name = e.target.dataset.name;
				// this.keyword = name;
			},
			actConfirm(){
				this.$u.route({
					type: 'back'
				})
			},
			goUser(e) {
				let uid = e.currentTarget.dataset.uid;
				if (uid > 1)
				{
				  uni.navigateTo({url: '/pages/user/index?uid=' + uid});
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.search {
		white-space: normal;
		word-break: break-all;
	}
	.search-header {
		background-color: #fff;
		padding: 30rpx;
		margin-bottom: 20rpx;
	}
	.search-content {
		overflow: hidden;
	}
	.section{
		background-color: #fff;
		padding:60rpx 30rpx;
		.u-empty{
			padding-top: 0;
		}
	}
	.result-item{
		padding: 30rpx;
		background-color: #fff;
		border-bottom: 1rpx solid #F3F4F6;
		&_info{
			margin-left: 30rpx;
			&--cell{
				margin-top: 6rpx;
				font-size: 24rpx;
				color: #909399;
				.label{
					display: inline-block;
					margin-right: 8rpx;
				}
			}
		}
	}
	.result-item:last-child{
		border-bottom: none;
	}
</style>
